<script setup lang="ts">
import { useDictOptions } from '@/hooks'

defineOptions({
  name: 'DictLabel',
})

const props = withDefaults(
  defineProps<{
    code?: string
    modelValue?: any
    options?: Array<any>
  }>(),
  {
    modelValue: undefined,
    code: undefined,
  },
)
const model = defineModel<string | boolean | number | Array<any>>()
const dictOptions = props.code ? useDictOptions(props.code) : toRef(props.options)

const getLabel = () => {
  const lst = dictOptions.filter(item => `${item.value}` === `${model.value}`)
  if (lst.length) {
    return lst[0].label
  }
  return '-'
}
</script>

<template>
  <span>{{ getLabel() }}</span>
</template>

<style lang="less" scoped>
</style>
